package com.heying.springcore.auto;

import com.heying.springcore.xml.Vehicle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;

@Component
public class Driver {

    @Value("bill")
    private String name;

    @Value("33")
    private int age;

    private Vehicle vehicle;

    public Vehicle getVehicle() {
        return vehicle;
    }

//    @Autowired//按照类型注入  spring的注解  两个结合使用
//    @Qualifier("tank")  //spring的注解

//    @Inject  //java的jsr标准注解，两个结合使用
//    @Named("car") //java的jsr标准注解

    @Resource(name = "car") // 默认就是按照名字找
    public void setVehicle(Vehicle vehicle) {
        this.vehicle = vehicle;
    }

    public Driver(String name, int age,Vehicle vehicle) {
        this.name = name;
        this.age = age;
        this.vehicle = vehicle;
    }

    public Driver() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Driver{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void drive(){
        System.out.println(this.age+"岁的"+this.name+"正在开车");
        vehicle.run();

    }
}
